package cn.szzsi.common.model;

import cn.szzsi.common.kit.CommonUtil;
import cn.szzsi.common.model.base.BaseNavigation;
import com.jfinal.kit.StrKit;
import javafx.scene.control.Skin;

import java.util.List;

/**
 * 实体类 - 导航
 * 
 */
public class Navigation extends BaseNavigation<Navigation> {

	private static final long serialVersionUID = 7618679206151166761L;

	public static final Navigation dao = new Navigation().dao();
	
	// 导航位置:顶部、中间、底部
	public enum Position {
		top, middle, bottom
	}
	
	/**
	 * 获取顶部Navigation对象集合（只包含isVisible=true的对象）
	 * 
	 * @return Navigation对象集合
	 * 
	 */
	public List<Navigation> getTopNavigationList() {
		String sql = "select * from  mall_navigation where position = ? and isVisible = ? and uid='"+ CommonUtil.PLATFROM_FLAG+"' order by orderList asc";
		return dao.find(sql, Position.top.ordinal(),true);
	}

	/**
	 * 获取商户顶部Navigation对象集合（只包含isVisible=true的对象）
	 *
	 * @return Navigation对象集合
	 *
	 */
	public List<Navigation> getBusinessTopNavigationList(String uid) {
		//System.out.println("uid--------------"+uid);
		if(StrKit.notBlank(uid)){
			String sql = "select * from  mall_navigation where position = ? and isVisible = ? and uid=? order by orderList asc";
			return dao.findByCache("BusinessNavigationList",uid.concat(Position.top.toString()),sql, Position.top.ordinal(),true,uid);
		}else{
			return null;
		}

	}

	/**
	 * 获取中间Navigation对象集合（只包含isVisible=true的对象）
	 * 
	 * @return Navigation对象集合
	 * 
	 */
	public List<Navigation> getMiddleNavigationList() {
		String sql = "select * from  mall_navigation where position = ? and isVisible = ? and uid='"+ CommonUtil.PLATFROM_FLAG+"' order by orderList asc";
		return dao.find(sql, Position.middle.ordinal(),true);
	}



	/**
	 * 获取该商户中间Navigation对象集合（只包含isVisible=true的对象）
	 *
	 * @return Navigation对象集合
	 *
	 */
	public List<Navigation> getBusinessMiddleNavigationList(String uid) {
		String sql = "select * from  mall_navigation where position = ? and isVisible = ? and uid = ? order by orderList asc";
		return dao.findByCache("BusinessNavigationList",uid.concat(Position.middle.toString()),sql, Position.middle.ordinal(),true,uid);
	}

	/**
	 * 获取底部Navigation对象集合（只包含isVisible=true的对象）
	 * 
	 * @return Navigation对象集合
	 * 
	 */
	public List<Navigation> getBottomNavigationList() {
		String sql = "select * from  mall_navigation where position = ? and isVisible = ?  and uid = '"+ CommonUtil.PLATFROM_FLAG+"' order by orderList asc";
		return dao.find(sql, Position.bottom.ordinal(),true);
	}
	/**
	 * 获取商户底部Navigation对象集合（只包含isVisible=true的对象）
	 *
	 * @return Navigation对象集合
	 *
	 */
	public List<Navigation> getBusinessBottomNavigationList(String uid) {
		String sql = "select * from  mall_navigation where position = ? and isVisible = ? and uid = ? order by orderList asc";
//		return dao.find(sql, Position.bottom.ordinal(),true,uid);
		return dao.findByCache("BusinessNavigationList",uid.concat(Position.bottom.toString()),sql, Position.bottom.ordinal(),true,uid);
	}
	public Position getPositionValue() {
		return Position.values()[getInt("position")];
	}

}
